package congen.xpand;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
//import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.mwe2.language.Mwe2StandaloneSetup;
import org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine;
import org.eclipse.emf.mwe2.language.mwe2.Module;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflow;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext;
import org.eclipse.emf.mwe2.runtime.workflow.WorkflowContextImpl;
import org.eclipse.xtext.naming.QualifiedName;
// Tieto su v BasicParserTest naviac:
//import org.eclipse.emf.ecore.EObject;
//import org.eclipse.emf.ecore.util.EcoreUtil;
//import org.eclipse.xtext.resource.XtextResource;
//import org.eclipse.xtext.resource.XtextResourceSet;

//import remotemm.RemotemmPackage;
//import ConnectorGenerator.CommunicationStyle.CommunicationStyle;
//import ConnectorGenerator.DRD.Component;
//import ConnectorGenerator.DRD.Connector;
//import ConnectorGenerator.DRD.DRDDocument;
//import ConnectorGenerator.DRD.Interface;
//import ConnectorGenerator.Signature.SignatureTerm;

import com.google.inject.Injector;

import congen.DRDLStandaloneSetup;

public class DrdToAlloyTest {

	public static void main(String[] args) {
		//RemotemmPackage remotemmPackage = RemotemmPackage.eINSTANCE;
		// IMPORTANT: Register the ecore metamodel
		ConnectorGenerator.DRD.DRDPackage.eINSTANCE.getEFactoryInstance();
		
		DRDLStandaloneSetup.doSetup();
		Injector injector = new Mwe2StandaloneSetup().createInjectorAndDoEMFRegistration();
		
		Mwe2ExecutionEngine engine = injector.getInstance(Mwe2ExecutionEngine.class);
		ResourceSet resourceSet = injector.getInstance(ResourceSet.class);
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());

		Resource moduleResource = resourceSet.getResource(URI.createURI("classpath:/congen/xpand/DrdToAlloyTest.mwe2"), true);
		Module module = (Module)moduleResource.getContents().get(0);
		
		URI fileURI = URI.createFileURI(new File("model/test.drd").getAbsolutePath());
		Resource inputRen = resourceSet.getResource(fileURI, true);

		Map<QualifiedName, Object> params = new HashMap<QualifiedName, Object>();
		// XXX: potrebujeme fully qualified name: params.put("outputDir", "output");
		IWorkflow workflow = (IWorkflow)engine.create(module, params);
		
		IWorkflowContext workflowCtx = new WorkflowContextImpl();
		workflowCtx.put("rootConnectorSpecification", inputRen.getContents().get(0));
		workflow.run(workflowCtx);
	}
}
